import axios from "axios";
import store from "@/store";
const request = axios.create({
  baseURL: "https://autumnfish.cn/", // https://autumnfish.cn/
  withCredentials: true
});

// 添加请求拦截器
request.interceptors.request.use(
  function(config) {
    if (store.state.userinfo) {
      // 不是登录接口
      // 携带token
      // config.headers.Authorization = store.state.userinfo.token;
      // config.headers.Cookie = store.state.userinfo.cookie;
      // console.log(config.headers.SetCookie);
    }
    return config;
  },
  function(error) {
    // 对请求错误做些什么
    // console.log(error);
    this.closeLoading();
    return Promise.reject(error);
  }
);
axios.interceptors.response.use(
  function(response) {
    // Any status code that lie within the range of 2xx cause this function to trigger
    // Do something with response data
    // console.log(response);
    return response;
  },
  function(error) {
    // Any status codes that falls outside the range of 2xx cause this function to trigger
    // Do something with response error
    // console.log(error);
    return Promise.reject(error);
  }
);
export default request;
